package com.tbsoft.ehr.dao.index;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.tbsoft.ehr.dao.BaseDaoImpl;
import com.tbsoft.ehr.model.IndexBuildTask;

public class IndexBuildTaskDaoImpl extends BaseDaoImpl<IndexBuildTask>
implements IndexBuildTaskDao{

	@SuppressWarnings("unchecked")
	@Override
	public List<IndexBuildTask> getNoRunBuildTaskList(final String taskType) {
		List list = getHibernateTemplate().executeFind(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Criteria criteria = session.createCriteria(IndexBuildTask.class);
				// (Criteria) DetachedCriteria.forClass(Resume.class);
				criteria.add(Restrictions.eq("taskStatus", "0"));
				criteria.add(Restrictions.ne("status", "D"));
				if(taskType != null && !taskType.isEmpty()){
					criteria.add(Restrictions.eq("taskType", taskType));
				}
				return criteria.list();
			}
		});
		return list;
	}
}
